<?php

class HelpAction extends Action {

    //列表
    function index() {
        $key =  $this->_param("key");
        $this->assign("key", $key);
        if($key){
            $where = "menu like '%".$key."%' or Id like '%".$key."%'";
        }else{
            $where ="";
        }
        $help = M("help");
        import('ORG.Util.Page'); // 导入分页类
        $count = $help->where($where)->count(); // 查询满足要求的总记录数 $map表示查询条件
        $Page = new Page($count, 10); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        // 进行分页数据查询
        $list = $help->where($where)->order('pid asc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('list', $list); // 赋值数据集
        $this->assign('page', $show); // 赋值分页输出

        foreach ($list as $key => $li) {
            $menu[$key] = $help->where("pid = " . $li['pid'])->getField("menu");
        }
        $this->assign("menu", $menu);

        $this->display();
    }

    //添加帮助信息
    function add() {
        $help = M("help");
        $menu = $help->where("pid=0")->select(); //获取一级菜单
        $this->assign("menu1", $menu);
        if ($_POST) {
            $data['pid'] = $_POST['pid'];
            $data['menu'] = $_POST['menu_name'];
            $data['fost'] = $_POST['fost'];
            $data['str'] = $_POST['str'];
            $data['content'] = $_POST['content'];
            $list = $help->add($data);
            if ($list) {
                $this->redirect("/Help");
            }
        } else {

            $this->display();
        }
    }

    //编辑帮助信息
    function edit($id = "") {
        $help = M("help");
        if ($_POST) { //有提交 执行修改
            $data['pid'] = $_POST['pid'];
            $data['menu'] = $_POST['menu_name'];
            $data['fost'] = $_POST['fost'];
            $data['str'] = $_POST['str'];
            $data['content'] = $_POST['content'];
            echo $id;
            $li = $help->where("Id = $id")->save($data);
            print_r($data);
            if ($li >= 1) {
                $this->redirect("/Help");
            } else {
                
            }
        } else { //没有提交 加载页面
            $this->assign("id", $id);
            $menu = $help->where("pid=0")->select(); //获取一级菜单
            $this->assign("menu1", $menu);
            $help = M("help");
            $list = $help->where("Id = $id")->select();
            $this->assign("list", $list);
            $this->assign("id", $id);
            $this->display();
        }
    }

    //删除帮助信息
    function del($id) {
        $help = M("help");
        $help->where("Id = $id")->delete();
        if ($help) {
            $this->redirect("/Help");
        }
    }

}

?>
